import React,{createRef} from 'react'
import Child from "./Child"


type Ipt = React.RefObject<HTMLInputElement>

class RefCom extends React.Component<any,any> {

    ipt:Ipt=createRef<HTMLInputElement>()
    child=createRef<any>()
    // ipt:Ipt
    // constructor(props:any){ 
    //     super(props) 
    //     this.ipt = createRef <HTMLInputElement>() 
    // }

    
    handleClick=()=> {
        console.log(this.ipt.current);
        this.ipt.current!.focus()
    }
    render(): React.ReactNode {
        return(
            <fieldset>
                <legend>Ref</legend>
                    <input type="text" ref={this.ipt} />
                    <Child ref={this.child}/>
                    <button onClick={this.handleClick}>点击</button>
            </fieldset>
        )
    }
}

export default RefCom